#ifndef PINS_H
#define PINS_H

#include <inttypes.h>
#include "Configuration.h"
#include "digital_pins.h"


/****************************************************************************************
*
* PINS CONFIG 1 - for standard printers
*
****************************************************************************************/

#if PINS_CONFIG == 1

// PORT A
#define X_STEP_PIN      0	
#define Y_STEP_PIN      1	
#define Z_STEP_PIN      2	
#define E1_STEP_PIN     3	
#define E2_STEP_PIN		4	
#define Z_MAX_PIN		5	
#define SD_EN_PIN		6
#define SD_SS_PIN		7

// PORT B
#define SPI_SS_PIN		8
#define AUX3_PIN		8
#define SPI_SCK_PIN		9
#define SPI_MOSI_PIN	10
#define SPI_MISO_PIN	11
#define AUX0_PIN		12
#define FAN1_PIN		13
#define FAN2_PIN		14
#define CONTROLLERFAN_PIN FAN2_PIN
#define E1_DIR_PIN		15	

// PORT C
#define X_ENABLE_PIN    16	
#define Y_ENABLE_PIN    17	
#define Z_ENABLE_PIN    18	
#define E1_ENABLE_PIN   19	
#define E2_ENABLE_PIN	20	
#define E_HALF_PIN		21	
#define SD_CD_PIN		22	
#define SD_WP_PIN		23

// PORT D
#define X_DIR_PIN       24	
#define Y_DIR_PIN       25	
#define RXD1_PIN		26	
#define TXD1_PIN		27	
#define E2_DIR_PIN		28	
#define X_HALF_PIN		29	
#define Y_HALF_PIN		30	
#define Z_HALF_PIN		31	

// PORT E
#define PDI_PIN			32
#define PDO_PIN			33
#define Z_DIR_PIN		34	
#define SW_BED_PIN		35	// Hard coded pwm
#define SW_EXT1_PIN		36	// Hard coded pwm
#define SW_EXT2_PIN		37	// Hard coded pwm
#define AUX1_PIN		38
#define CONTROL_BUTTON_PIN  38	// Hard coded input
#define AUX2_PIN		39

// PORT F
#define BED_THERM_PIN	40
#define E1_THERM_PIN	41
#define E2_THERM_PIN	42
#define STRMON_PIN		43
#define TCK_PIN			44
#define TMS_PIN			45
#define TDO_PIN			46
#define TDI_PIN			47

// PORT G

#define X_MIN_PIN          48
#define X_MAX_PIN          -1
#define Y_MIN_PIN          49
#define Y_MAX_PIN          -1
#define Z_MIN_PIN          50
// Z_MAX_PIN DEFINED to pin 5
#define AUX_PG4_PIN			51
#define AUX_PG3_PIN			52

// HARD CODED ANALOG INPUTS
#define TEMP_BED_PIN        0   // MUST USE ANALOG INPUT NUMBERING NOT DIGITAL OUTPUT NUMBERING!!!!!!!!! (pin 33 extruder)
#define TEMP_EXT1_PIN		1
#define TEMP_EXT2_PIN		2	

//List of pins which is free to change
const uint8_t free_pins[] = { AUX0_PIN, AUX1_PIN, AUX2_PIN };

#endif // END PINS_CONFIG == 1

/****************************************************************************************
*
* PINS CONFIG 2 - for maxi printers master unit
*
****************************************************************************************/

#if PINS_CONFIG == 2

// PORT A
#define X_STEP_PIN      0
#define Y_STEP_PIN      1
#define Z_STEP_PIN      2
#define E1_STEP_PIN     3
#define E2_STEP_PIN		4
#define Z_MAX_PIN		5
#define SD_EN_PIN		6
#define SD_SS_PIN		7

// PORT B
#define SPI_SS_PIN		8
#define AUX3_PIN		8
#define SPI_SCK_PIN		9
#define SPI_MOSI_PIN	10
#define SPI_MISO_PIN	11
#define AUX0_PIN		12
#define FAN1_PIN		13
#define FAN2_PIN		14
#define CONTROLLERFAN_PIN FAN2_PIN
#define E1_DIR_PIN		15

// PORT C
#define X_ENABLE_PIN    16
#define Y_ENABLE_PIN    17
#define Z_ENABLE_PIN    18
#define E1_ENABLE_PIN   19
#define E2_ENABLE_PIN	20
#define E_HALF_PIN		21
#define SD_CD_PIN		22
#define SD_WP_PIN		23

// PORT D
#define X_DIR_PIN       24
#define Y_DIR_PIN       25
#define RXD1_PIN		26
#define TXD1_PIN		27
#define E2_DIR_PIN		28
#define X_HALF_PIN		29
#define Y_HALF_PIN		30
#define Z_HALF_PIN		31

// PORT E
#define PDI_PIN			32
#define PDO_PIN			33
#define Z_DIR_PIN		34
#define SW_BED_PIN		35	// Hard coded pwm
#define SW_EXT1_PIN		36	// Hard coded pwm
#define SW_EXT2_PIN		37	// Hard coded pwm
#define AUX1_PIN		38
#define CONTROL_BUTTON_PIN  38	// Hard coded input
#define AUX2_PIN		39

// PORT F
#define BED_THERM_PIN	40
#define E1_THERM_PIN	41
#define E2_THERM_PIN	42
#define STRMON_PIN		43
#define TCK_PIN			44
#define TMS_PIN			45
#define TDO_PIN			46
#define TDI_PIN			47

// PORT G

#define X_MIN_PIN          48
#define X_MAX_PIN          -1
#define Y_MIN_PIN          49
#define Y_MAX_PIN          -1
#define Z_MIN_PIN          50
// Z_MAX_PIN DEFINED to pin 5
#define AUX_PG4_PIN			51
#define AUX_PG3_PIN			52

// HARD CODED ANALOG INPUTS
#define TEMP_BED_PIN        0   // MUST USE ANALOG INPUT NUMBERING NOT DIGITAL OUTPUT NUMBERING!!!!!!!!! (pin 33 extruder)
#define TEMP_EXT1_PIN		1
#define TEMP_EXT2_PIN		2

//List of pins which is free to change
const uint8_t free_pins[] = { AUX0_PIN, AUX1_PIN, AUX2_PIN };

#endif // END PINS_CONFIG == 2

/****************************************************************************************
*
* PINS CONFIG 3 - for maxi printers master unit
*
****************************************************************************************/
#if PINS_CONFIG == 3

// PORT A
#define X_STEP_PIN      0
#define Y_STEP_PIN      1
#define Z_STEP_PIN      2
#define E1_STEP_PIN     3
#define E2_STEP_PIN		4
#define SFSTOP_PIN		5
#define Z_MAX_PIN		-1
#define SD_EN_PIN		6
#define SD_SS_PIN		7

// PORT B
#define SPI_SS_PIN		8
#define AUX3_PIN		8
#define SPI_SCK_PIN		9
#define SPI_MOSI_PIN	10
#define SPI_MISO_PIN	11
#define AUX0_PIN		12
#define FAN1_PIN		13
#define DOOR_BLOCK_PIN	14
#define E1_DIR_PIN		15

// PORT C
#define X_ENABLE_PIN    16
#define Y_ENABLE_PIN    17
#define Z_ENABLE_PIN    18
#define E1_ENABLE_PIN   19
#define E2_ENABLE_PIN	20
#define E_ALARM_PIN		21
#define SD_CD_PIN		22
#define SD_WP_PIN		23

// PORT D
#define X_DIR_PIN       24
#define Y_DIR_PIN       25
#define RXD1_PIN		26
#define TXD1_PIN		27
#define E2_DIR_PIN		28
#define X_ALARM_PIN		29
#define Y_ALARM_PIN		30
#define Z_ALARM_PIN		31

// PORT E
#define PDI_PIN			32
#define PDO_PIN			33
#define Z_DIR_PIN		34
#define SW_BED_PIN		35	// Hard coded pwm
#define SW_EXT1_PIN		36	// Hard coded pwm
#define SW_EXT2_PIN		37	// Hard coded pwm
#define AUX1_PIN		38
#define CONTROL_BUTTON_PIN  38	// Hard coded input
#define AUX2_PIN		39

// PORT F
#define BED_THERM_PIN	40
#define E1_THERM_PIN	41
#define E2_THERM_PIN	42
#define STRMON_PIN		43
#define TCK_PIN			44
#define TMS_PIN			45
#define TDO_PIN			46
#define TDI_PIN			47

// PORT G

#define X_MIN_PIN          48
#define X_MAX_PIN          -1
#define Y_MIN_PIN          49
#define Y_MAX_PIN          -1
#define Z_MIN_PIN          50
// Z_MAX_PIN DEFINED to pin 5
#define AUX_PG4_PIN			51
#define AUX_PG3_PIN			52

// HARD CODED ANALOG INPUTS
#define TEMP_BED_PIN        0   // MUST USE ANALOG INPUT NUMBERING NOT DIGITAL OUTPUT NUMBERING!!!!!!!!! (pin 33 extruder)
#define TEMP_EXT1_PIN		1
#define TEMP_EXT2_PIN		2

//List of pins which is free to change
const uint8_t free_pins[] = { AUX0_PIN, AUX1_PIN, AUX2_PIN };

#endif // END PINS_CONFIG == 3

/****************************************************************************************
*
* PINS CONFIG 4 - for maxi printers slave unit
*
****************************************************************************************/
#if PINS_CONFIG == 4

// PORT A
#define OUT_0_PIN		0
#define OUT_2_PIN		1
#define OUT_4_PIN		2
#define OUT_6_PIN		3
#define OUT_8_PIN		4
#define SF_STOP_PIN		5
//#define SD_EN_PIN		6
//#define SD_SS_PIN		7

// PORT B
//#define SPI_SS_PIN		8
//#define AUX3_PIN		8
//#define SPI_SCK_PIN		9
//#define SPI_MOSI_PIN	10
//#define SPI_MISO_PIN	11
//#define AUX0_PIN		12
#define FAN1_PIN		13
#define FAN2_PIN		14
#define IN_7_PIN		15

// PORT C
#define OUT_1_PIN		16
#define OUT_3_PIN		17
#define OUT_5_PIN		18
#define OUT_7_PIN		19
#define OUT_9_PIN		20
#define IN_6_PIN			21
//#define SD_CD_PIN		22
//#define SD_WP_PIN		23

// PORT D
#define IN_1_PIN			24
#define IN_3_PIN       25
#define RXD1_PIN		26
#define TXD1_PIN		27
#define IN_9_PIN		28
#define IN_0_PIN			29
#define IN_2_PIN			30
#define IN_4_PIN		31

// PORT E
//#define PDI_PIN			32
//#define PDO_PIN			33
#define IN_5_PIN		34
#define SW_BED_PIN		35	// Hard coded pwm
#define SW_EXT1_PIN		36	// Hard coded pwm
#define SW_EXT2_PIN		37	// Hard coded pwm
//#define AUX1_PIN		38
//#define CONTROL_BUTTON_PIN  38	// Hard coded input
//#define AUX2_PIN		39

// PORT F
#define BED_THERM_PIN	40
#define E1_THERM_PIN	41
#define E2_THERM_PIN	42
//#define STRMON_PIN		43
//#define TCK_PIN			44
//#define TMS_PIN			45
//#define TDO_PIN			46
//#define TDI_PIN			47

// PORT G

//#define X_MIN_PIN          48
//#define X_MAX_PIN          -1
//#define Y_MIN_PIN          49
//#define Y_MAX_PIN          -1
//#define Z_MIN_PIN          50
// Z_MAX_PIN DEFINED to pin 5
//#define AUX_PG4_PIN			51
//#define AUX_PG3_PIN			52

// HARD CODED ANALOG INPUTS
#define TEMP_BED_PIN        0   // MUST USE ANALOG INPUT NUMBERING NOT DIGITAL OUTPUT NUMBERING!!!!!!!!! (pin 33 extruder)
#define TEMP_EXT1_PIN		1
#define TEMP_EXT2_PIN		2

//List of pins which is free to change
//const uint8_t free_pins[] = { AUX0_PIN, AUX1_PIN, AUX2_PIN };

#endif // END PINS_CONFIG == 4

//=====================================================================================================================

#endif
